package com.shixun.milktea.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shixun.milktea.entity.Mt;
import com.shixun.milktea.entity.Order;
import com.shixun.milktea.entity.Sort;
import com.shixun.milktea.mapper.SortMapper;
import com.shixun.milktea.service.SortService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shixun.milktea.vo.PageVo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zrs
 * @since 2022-06-07
 */
@Service
public class SortServiceImpl extends ServiceImpl<SortMapper, Sort> implements SortService {
    @Autowired
    SortMapper sortMapper;

    /**
     * 查询所有分类
     * @return
     */
    public List<Sort> queryAllSort() {
        QueryWrapper<Sort> qw=new QueryWrapper<>();
        return sortMapper.selectList(qw);
    }

    /**
     * 根据分类id查询分类
     * @param sortId
     * @return
     */
    public Sort queryBySortId(int sortId){
        Sort sort = sortMapper.selectById(sortId);
        return sort;
    }

    @Override
    public List<Sort> getAllSortAndMt() throws Exception {
        List<Sort> allSortAndMt = sortMapper.findAllSortAndMt();
        return allSortAndMt;
    }

    /**
     * 分类分页查询
     * @param pageVo
     * @return
     * @throws Exception
     */
    @Override
    public PageInfo getSortPage(PageVo pageVo) throws Exception {
        System.out.println(pageVo.getPageNo()+"   "+pageVo.getPageSize());
        PageHelper.startPage(pageVo.getPageNo(),pageVo.getPageSize());
        List<Integer> sortIdList = sortMapper.selectAllSortId();

        List<Sort> list = new ArrayList<>();
        for(Integer sortId:sortIdList){
            list.add(sortMapper.findSortById(sortId));
        }

        PageInfo<Sort> orderPageInfo = new PageInfo<>(list);
        return orderPageInfo;
    }


}
